#include "ptr_xy.h"

using namespace std;
using namespace opsrc::stdf;
#include "rectype.h"
#include "util.h"

#include "nmfield.h"
#include "nmfield.cpp"

#include "cnfield.h"

#include "nmarrfield.h"
#include "nmarrfield.cpp"

#include <sstream>
#include <string>
#include <map>

map<string,int> PtrXY::seq_count;

PtrXY::PtrXY()
{
    count_increased = false;
}


PtrXY::PtrXY(stdf_rec _stdfrec,  int _reclen, std::ios::pos_type _fileRecFirstBytePosition, int _orderindex, endian e, char* buf)
:Ptr(_stdfrec, _reclen, _fileRecFirstBytePosition, _orderindex, e, buf){
    count_increased = false;
}


PtrXY::~PtrXY() {
}

const StdfField<int> PtrXY::getXCoordinate() const {
    return x_coord;
}

void PtrXY::setXCoordinate(StdfField<int> xcoord) {
    x_coord = xcoord;
}

const StdfField<int> PtrXY::getYCoordinate() const {
    return y_coord;
}

void PtrXY::setYCoordinate(StdfField<int> ycoord) {
    y_coord = ycoord;
}

const int PtrXY::getSeqId() {
    // Compute seq_id
    if (!count_increased) {
        stringstream ss;
        ss << "PTR." << test_num.getData() << "." << x_coord.getData() << "." << y_coord.getData();
        string key = ss.str();
        //if( seq_count.find(key) != seq_count.end() ) {
            seq_count[key]++;
            seq_id = seq_count[key];
        //} else {
        //    seq_count[key] = 0;
        //}
        count_increased = true;
    }
    return seq_id;
}

void PtrXY::setSeqId(int seqid) {
    seq_id = seqid;
}

